package pers.qianyu.month_202011.date_20201126;

/**
 * 234. 回文链表
 * https://leetcode-cn.com/problems/palindrome-linked-list/
 *
 * @author mizzle rain
 * @date 2020-11-26 23:04
 */
public class IsPalindrome {
    private ListNode left;

    public boolean isPalindrome(ListNode head) {
        this.left = head;
        return recur(head);
    }

    /**
     * 递归解法
     */
    private boolean recur(ListNode head) {
        if (head == null) {
            return true;
        }
        boolean res = recur(head.next);
        res = res && (head.val == left.val);
        left = left.next;
        return res;
    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
}
